package com.demo.serviceImpl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.entity.ScoreVo;
import com.demo.entity.Totalscore;
import com.demo.entity.TotalscoreExample;
import com.demo.entity.TotalscoreExample.Criteria;
import com.demo.mapper.TotalscoreMapper;
import com.demo.service.TotalScoreService;
@Service
public class TotalScoreServiceImpl implements TotalScoreService{
	@Autowired
	private TotalscoreMapper totalscoreMapper;
	// 查询成绩信息 包括课程和学生信息
	@Override
	public List<ScoreVo> selectAllScoreVo() throws Exception {
		return totalscoreMapper.AllScoreVo();
	}
	@Override
	public int addTotalScore(Totalscore totalscore) throws Exception {
		//插入成绩之前先判断该学生对应的课程是否已经录入，是则抛出异常，否则插入成绩信息
		TotalscoreExample example = new TotalscoreExample();
		Criteria createCriteria = example.createCriteria();
		
		createCriteria.andStudentidEqualTo(totalscore.getStudentid());
		createCriteria.andCourseidEqualTo(totalscore.getCourseid());
		List<Totalscore> selectByExample = totalscoreMapper.selectByExample(example);
		if (selectByExample != null && selectByExample.size()>0){
			throw new Exception("该学生此课程的成绩已录入，如需修改请更新！");
		}else {
			return totalscoreMapper.insert(totalscore);
		}
	}
	@Override
	public Totalscore selectTotalScoreById(String id) throws Exception {
		return totalscoreMapper.selectByPrimaryKey(id);
	}
	@Override
	public int deleteTotalScoreById(String id) throws Exception {
		return totalscoreMapper.deleteByPrimaryKey(id);
	}
	@Override
	public int updateTotalScore(Totalscore totalscore) throws Exception {
		return totalscoreMapper.updateByPrimaryKey(totalscore);
	}
	@Override
	public List<Totalscore> selectAllTotalScore() throws Exception {
		TotalscoreExample example = new TotalscoreExample();
		return totalscoreMapper.selectByExample(example);
	}
	@Override
	public List<Totalscore> AllTotalScoreVo() throws Exception {
		return totalscoreMapper.selectAllTotalScoreVo();
	}
	@Override
	public List<ScoreVo> findScoreVoscoc(ScoreVo scoreVo) throws Exception {
		return totalscoreMapper.findScoreVoscoc(scoreVo);
	}
	
}
